package com.team.childapp.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.text.format.DateFormat;

import java.util.Date;

/**
 * Create on: 2024/8/4
 * by Mr.Zhu
 * Description: 通用公共累
 */
public class CommonU {
    public static String FORMAT_YYYY = "yyyy-MM-dd HH:mm:ss";
    /**
     * 获取当前应用版本号
     *
     * @param context
     * @return
     */
    public static int getVersionCode(Context context) {
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            return packageInfo.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return 0;
    }

    /**
     * 获取当前时间
     *
     * @return
     */
    public static String date() {
        return DateFormat.format(FORMAT_YYYY, new Date()).toString();
    }

    public static boolean isPunctuation(char ch) {
        if (isCjkPunc(ch)) {
            return true;
        }
        if (isEnPunc(ch)) {
            return true;
        }

        if (0x2018 <= ch && ch <= 0x201F) {
            return true;
        }
        if (ch == 0xFF01 || ch == 0xFF02) {
            return true;
        }
        if (ch == 0xFF07 || ch == 0xFF0C) {
            return true;
        }
        if (ch == 0xFF1A || ch == 0xFF1B) {
            return true;
        }
        if (ch == 0xFF1F || ch == 0xFF61) {
            return true;
        }
        if (ch == 0xFF0E) {
            return true;
        }
        if (ch == 0xFF65) {
            return true;
        }

        return false;
    }


    public static boolean isCjkPunc(char ch) {
        if (0x3001 <= ch && ch <= 0x3003) {
            return true;
        }
        if (0x301D <= ch && ch <= 0x301F) {
            return true;
        }

        return false;
    }
    public static boolean isEnPunc(char ch) {
        if (0x21 <= ch && ch <= 0x22) {
            return true;
        }
        if (ch == 0x27 || ch == 0x2C) {
            return true;
        }
        if (ch == 0x2E || ch == 0x3A) {
            return true;
        }
        if (ch == 0x3B || ch == 0x3F) {
            return true;
        }

        return false;
    }
}
